import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-06-01
 * Time: 20:02
 */
public class Main {
    public static int searchInsert(int[] nums, int target) {
        int i= Arrays.binarySearch(nums,target);//二分查找

        return i>0? i :-i;
    }
    public static void main(String[] args) {
        int[]nums={1,3,5,6};
        searchInsert(nums,2);

    }
    public int strStr(String haystack, String needle) {

        int i1=haystack.indexOf(needle);//返回第一次出现的索引，没有则返回-1
        return i1;

    }

    public static int removeElement(int[] nums, int val) {
        //模拟栈的实现
        int[] arr=new int [nums.length];
        int k=0;
        for(int i=0;i<nums.length;i++){
            if(nums[i]!=val){
                arr[k++]=nums[i];
            }
        }
        for(int x:arr){
            System.out.print(x+"\t");
        }
        return k;
//        StringBuilder st=new StringBuilder();
//        for (int i = 0; i < nums.length; i++) {
//            if(nums[i]!=val){
//                st.append(nums[i]);
//            }
//        }
//        return st.length();

    }
    public static void main1(String[] args) {
        int[] nums={3,2,2,3};
        System.out.println(removeElement(nums,3));


    }
}